	//获取总页数
	$.getJSON('../../AllPages',{
		flag:'manager'
	},function(data,status){
		if(status){
			console.log(data[0].pages);
			var pages = data[0].pages;
			
			$('#pageLimit').bootstrapPaginator({
				currentPage : 1,
				totalPages : parseInt(pages),
				size : "normal",
				bootstrapMajorVersion : 3,
				alignment : "right",
				numberOfPages : 5,
				itemTexts : function(type, page, current) {
					switch (type) {
					case "first":
						return "首页";
					case "prev":
						return "上一页";
					case "next":
						return "下一页";
					case "last":
						return "末页";
					case "page":
						return page;
					}
				},

				onPageClicked : function(event, originalEvent, type, page) {
					console.log("1:" + page);
					
					showPage(page);
					
				},
			});
			
			
			
		}
	});
	
	

	//显示第一页
	showPage(1);




//show manager list
function showPage(page){
	
	$.getJSON('../../ManagerDeal',{
		flag:1,
		pageNumber:page,
		showNumber:5
		},function(data,status){
		if(status){
			
			$('tbody').empty();
			for(var i=0;i<data.length;i++){
				
				var id = data[i].id;
				
				$('tbody').append('<tr><td>'+id+'</td><td>'+data[i].name+'</td>'
						+'<td data-manager-id='+id+'></td><td>'
						+'<div class="btn-group"><button type="button" class="btn btn-default" data-manager-id="'+id+'"  onclick="up_manager(this)">修改权限</button>'
						+'<button type="button" class="btn btn-default testtest" data-manager-id="'+id+'"  onclick="del_manager(this)">删除</button></div></td></tr>');
				
				$.each(data[i].power,function(k,v){
					$('td[data-manager-id='+id+']').append(v+',');
				});
				
				
				
			}
			
		}
	});
	
}

function up_manager(obj){
	$('.up-manager').css('display','none');
	
	var id = $(obj).attr('data-manager-id');
	console.log(id);
	
	$('.u-select').attr('checked',false);
	
	$.getJSON('../../ManagerDeal',{
		flag:2,
		id:id
	},function(data,status){
		if(status){
			var info = data[0];
			$('#u-id').val(info.id);
			$('#u-ids').val(info.id);
			$('#u-userName').val(info.name);
			$('#u-password').val(info.passwd);
			$.each(info.power,function(k,v){
				$('.'+v).attr('checked',true);
			});
		}
	});
	
	$('.up-manager').css('display','block');
	
}

function del_manager(obj){
	var id = $(obj).attr('data-manager-id');
	if(confirm('请先把权限移除，才能删除。\n确定删除？')){
		$.getJSON('../../ManagerDeal',{
			flag:4,
			id:id
			},function(data,status){
			if(status){
				alert(data[0].name);
				$(obj).parent().parent().parent().remove();
			}
		});
	}
}

$('.add-btn').click(function(){
	$('.add-manager').css('display','block');
});

$(function(){
	

	$('.u-sure-btn').click(function(){
		var datas = $('.up-form').serialize();
		console.log(datas);
		$.getJSON('../../ManagerDeal',datas,function(data,status){
			if(status){
				alert(data[0].name);
				$('.up-manager').css('display','none');
				window.location.reload(true);
			}
		});
		
	});


	$('.a-sure-btn').click(function(){
		var datas = $('.add-form').serialize();
		console.log(datas);
		$.getJSON('../../ManagerDeal',datas,function(data,status){
			if(status){
				alert(data[0].name);
				$('.add-manager').css('display','none');
				window.location.reload(true);
			}
		});
		
	});
	
	
})



														